import { Effect, ImmerReducer, Reducer, Subscription } from 'umi';
import {fileDelete, fileList} from '../services/index';

export interface IndexModelState {
    fileLists: string;
}

export interface IndexModelType {
  namespace: 'file';
  state: IndexModelState;
  effects: {
    fileList: Effect;
    fileDelete:Effect;
  };
  reducers: {
    save: Reducer<IndexModelState>;
    // 启用 immer 之后
    // save: ImmerReducer<IndexModelState>;
  };
  subscriptions?: { setup: Subscription };
}

const IndexModel: IndexModelType = {
  namespace: 'file',

  state: {
    fileLists: '',
  },

  effects: {
    *fileList({ payload }, { call, put , select}) {
        let result = yield call(fileList,payload.page,payload.originalname,payload.type);
        yield put({
            type:'save',
            payload:{
                fileLists:result
            }
          })
      
    },

    *fileDelete({ payload }, { call, put , select}) {
      let result = yield call(fileDelete,payload.indexModuArr);
      // yield put({
      //     type:'save',
      //     payload:{
      //         fileLists:result
      //     }
      //   })
     
  },
  },


  
  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
 
  },

};

export default IndexModel;